home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / commands / de / de.h < prev    next >
C/C++ Source or Header  |  1990-07-23  |  8KB  |  324 lines

  1. /****************************************************************/
  2. /*                                */
  3. /*    de.h                            */
  4. /*                                */
  5. /*        Definitions for the "Disk editor".        */
  6. /*                                */
  7. /****************************************************************/
  8. /*  origination         1989-Jan-15        Terrence W. Holm    */
  9. /****************************************************************/
  10.  
  11.  
  12. /****************************************************************/
  13. /*                                */
  14. /*    de(1)                            */
  15. /*                                */
  16. /*  This is the MINIX disk editor. It allows the user to    */
  17. /*  observe and modify a file system. It can also be used    */
  18. /*  to recover unlink(2)'ed files                */
  19. /*                                */
  20. /*  See the de(1) man page.                    */
  21. /*                                */
  22. /****************************************************************/
  23.  
  24.  
  25. /****************************************************************/
  26. /*                                */
  27. /*    de           Copyright  Terrence W. Holm  1989    */
  28. /*                                */
  29. /* This program was written for users of the Minix operating    */
  30. /* system, and in the spirit of other public domain software    */
  31. /* written for said system, this source code is made available    */
  32. /* at no cost to everyone. I assume no responsibility for    */
  33. /* damage to file systems caused by this program.        */
  34. /*                                */
  35. /* This program (one .h, five .c's and a "man" page) may be    */
  36. /* copied and/or modified subject to (1) no charge must be    */
  37. /* made for distribution, other than for the medium, (2) all    */
  38. /* modified sources must be clearly marked as such, (3) all    */
  39. /* sources must carry this copyright.                */
  40. /*                                */
  41. /****************************************************************/
  42.  
  43.  
  44. /****************************************************************/
  45. /*                                */
  46. /*    files                            */
  47. /*                                */
  48. /*        de.h        Definitions            */
  49. /*        de.c        The main loop            */
  50. /*        de_stdin.c        Character input routines    */
  51. /*        de_stdout.c        Output routines            */
  52. /*        de_diskio.c        File system read/write        */
  53. /*        de_recover.c    File restoration routines    */
  54. /*                                */
  55. /*        de.1        "Man" page            */
  56. /*        Makefile        For "make"            */
  57. /*        README        Installation help        */
  58. /*                                */
  59. /*                                */
  60. /*    fs/path.c was modified to support the 'x' command.    */
  61. /*    fs/link.c and fs/open.c were changed for 'X'.        */
  62. /*                                */
  63. /****************************************************************/
  64.  
  65.  
  66. /*  General constants  */
  67.  
  68. #define   MAX_STRING    60        /*  For all input lines    */
  69. #define   MAX_PREV    8        /*  For 'p' command    */
  70. #define   SEARCH_BUFFER (4*K)        /*  For '/' and 'n'    */
  71.  
  72.  
  73. /*  Files  */
  74.  
  75. #define   TMP      "/tmp"        /*  For "-r" output    */
  76. #define   DEV       "/dev"        /*  Where devices are    */
  77.  
  78.  
  79. /*  a.out header constants  (see a.out.h, if you have it)  */
  80.  
  81. #if (CHIP == INTEL)
  82. #define   A_OUT    0x0301
  83. #define   SPLIT    0x0420
  84. #endif
  85.  
  86. #if (CHIP == M68000)
  87. #define   A_OUT    0x0301
  88. #define   SPLIT       0x0B20
  89. #endif
  90.  
  91.  
  92. /*  Each buffer is 1k.  In WORD mode 16 words (32 bytes) can be    */
  93. /*  displayed at once. In BLOCK mode 1K bytes can be displayed.    */
  94. /*  In MAP mode 2048 bits (256 bytes) are displayed.        */
  95.  
  96. #define   K        1024        /*  STD_BLK        */
  97. #define   K_MASK    (~(K-1))    /*  Round to K boundary    */
  98. #define   K_SHIFT    10        /*  Ie. 1<<10 = K    */
  99. #define   PAGE_MASK    0x1f        /*  Word mode: 32 bytes    */
  100. #define   PAGE_SHIFT    5        /*  Ie. 1<<5 = 32    */
  101. #define   MAP_BITS_PER_BLOCK (8 * K)    /*  1k block, 8192 bits */
  102. #define   MAP_MASK    0xff        /*  256 bytes/screen    */
  103.  
  104.  
  105.  
  106. /*  Terminal i/o codes  */
  107.  
  108. #define   CTRL_D    '\004'        /*  ASCII ^D        */
  109. #define   BELL        '\007'        /*  ASCII bell code     */
  110. #define   BS        '\010'        /*  ASCII back space    */
  111. #define   CTRL_U    '\025'        /*  ASCII ^U        */
  112. #define      ESCAPE      '\033'        /*  ASCII escape code    */
  113. #define   DEL           '\177'        /*  ASCII delete code   */
  114.  
  115.  
  116. /*  Input escape codes generated by the    Minix console.    */
  117. /*  Format: ESC [ X.                     */
  118.  
  119. #define   ESC_HOME    ('H' + 0x80)
  120. #define   ESC_UP    ('A' + 0x80)
  121. #define   ESC_PGUP    ('V' + 0x80)
  122. #define   ESC_LEFT    ('D' + 0x80)
  123. #define   ESC_5        ('G' + 0x80)
  124. #define   ESC_RIGHT    ('C' + 0x80)
  125. #define   ESC_END    ('Y' + 0x80)
  126. #define   ESC_DOWN    ('B' + 0x80)
  127. #define   ESC_PGDN    ('U' + 0x80)
  128. #define   ESC_PLUS    ('T' + 0x80)
  129. #define   ESC_MINUS    ('S' + 0x80)
  130.  
  131.  
  132. /*  Graphic box codes - only applicable for console display  */
  133. /*  in visual mode "map".                     */
  134.  
  135. #if (CHIP == INTEL)
  136. #define   BOX_CLR    ' '        /*  Empty box        */
  137. #define   BOX_ALL    '\333'        /*  Filled box        */
  138. #define   BOX_TOP    '\337'        /*  Filled upper half    */
  139. #define   BOX_BOT    '\334'        /*  Filled lower half   */
  140. #endif
  141.  
  142. #if (CHIP == M68000)
  143. /*  Please change these.  */
  144. #define   BOX_CLR    ' '        /*  Empty box        */
  145. #define   BOX_ALL    '='        /*  Filled box        */
  146. #define   BOX_TOP    '-'        /*  Filled upper half    */
  147. #define   BOX_BOT    '_'        /*  Filled lower half   */
  148. #endif
  149.  
  150.  
  151. /*  Move positions for the output display.  */
  152.  
  153. #define   STATUS_COLUMN     2
  154. #define   STATUS_LINE    0
  155. #define   BLOCK_COLUMN     4
  156. #define   BLOCK_LINE     4
  157. #define   INFO_COLUMN     30
  158. #define   INFO_LINE     BLOCK_LINE
  159. #define   PROMPT_COLUMN     0
  160. #define   PROMPT_LINE     23
  161. #define   WARNING_COLUMN 10
  162. #define   WARNING_LINE   10
  163.  
  164.  
  165.  
  166. /*  Values returned by Process() and Get_Filename()  */
  167.  
  168. #define   OK          0        /*  No update required    */
  169. #define   REDRAW      1        /*  Redraw whole screen    */
  170. #define   REDRAW_POINTERS 2        /*  Redraw just ptrs    */
  171. #define   ERROR          3        /*  Beep        */
  172.  
  173.  
  174. /*  Visual modes  */
  175.  
  176. #define   WORD       1
  177. #define   BLOCK    2
  178. #define   MAP       3
  179.  
  180.  
  181. typedef  struct  de_state        /*  State of disk ed.    */
  182.   {
  183.   /*  Information from super block  */
  184.  
  185.   unsigned inodes;            /*  Number of i-nodes    */
  186.   unsigned zones;            /*  Total # of blocks    */
  187.   unsigned inode_maps;            /*  I-node map blocks    */
  188.   unsigned zone_maps;            /*  Zone map blocks    */
  189.   unsigned inode_blocks;        /*  I-node blocks    */
  190.   unsigned first_data;            /*  Total non-data blks    */
  191.  
  192.   unsigned inodes_in_map;        /*  Bits in i-node map    */
  193.   unsigned zones_in_map;        /*  Bits in zone map    */
  194.  
  195.   /*  Information from map blocks  */
  196.  
  197.   char inode_map[ I_MAP_SLOTS * K ];
  198.   char zone_map[ ZMAP_SLOTS * K ];
  199.  
  200.   /*  Information for current block  */
  201.  
  202.   off_t address;            /*  Current address    */
  203.   off_t last_addr;            /*  For erasing ptrs    */
  204.   unsigned block;            /*  Current block (1K)    */
  205.   unsigned offset;            /*  Offset within block    */
  206.  
  207.   char buffer[ K ];
  208.  
  209.   /*  Display state  */
  210.  
  211.   int  mode;                /*  WORD, BLOCK or MAP    */
  212.   int  output_base;            /*  2, 8, 10, or 16    */
  213.  
  214.   /*  Search information  */
  215.  
  216.   char search_string[ MAX_STRING + 1 ];    /*  For '/' and 'n'    */
  217.   off_t prev_addr[ MAX_PREV ];        /*  For 'p' command    */
  218.   int   prev_mode[ MAX_PREV ];
  219.  
  220.   /*  File information  */
  221.  
  222.   char *device_name;            /*  From command line    */
  223.   int   device_d;
  224.   int   device_mode;            /*  O_RDONLY or O_RDWR    */
  225.   unsigned device_size;            /*  Number of blocks    */
  226.  
  227.   char  file_name[ MAX_STRING + 1 ];    /*  For 'w' and 'W'    */
  228.   FILE *file_f;
  229.   int   file_written;            /*  Flag if written to    */
  230.  
  231.   }  de_state;
  232.  
  233.  
  234.  
  235. /*  Forward references for external routines  */
  236.  
  237. /*  libc.a  */
  238.  
  239. struct passwd *getpwuid();
  240. struct group *getgrgid();
  241. char *ctime();
  242. char *getenv();
  243. char *tgetstr();
  244. char *tgoto();
  245. char *ttyname();
  246. FILE *fopen();
  247. off_t lseek();
  248.  
  249.  
  250. /*  de.c  */
  251.  
  252. void  main();
  253. int   Process();
  254.  
  255. void  Push();
  256. int   Get_Filename();
  257. int   Get_Count();
  258. int   Str_Int();
  259. int   In_Use();
  260. ino_t Find_Inode();
  261. void  Exec_Shell();
  262. void  Sigint();
  263. void  Error();
  264.  
  265.  
  266. /*  de_stdin.c  */
  267.  
  268. void  Save_Term();
  269. void  Set_Term();
  270. void  Reset_Term();
  271. int   Get_Char();
  272. char *Get_Line();
  273. int   Arrow_Esc();
  274.  
  275.  
  276. /*  de_stdout.c  */
  277.  
  278. int   Init_Termcap();
  279. void  Goto();
  280. void  Draw_Help_Screen();
  281. void  Wait_For_Key();
  282. void  Draw_Prompt();
  283. void  Erase_Prompt();
  284.  
  285. void  Draw_Screen();
  286. void  Draw_Strings();
  287. void  Block_Type();
  288. void  Draw_Words();
  289. void  Draw_Info();
  290. void  Draw_Block();
  291. void  Draw_Map();
  292.  
  293. void  Draw_Pointers();
  294. void  Draw_Offset();
  295. void  Word_Pointers();
  296. void  Block_Pointers();
  297. void  Map_Pointers();
  298.  
  299. void  Print_Number();
  300. void  Print_Ascii();
  301. void  Warning();
  302.  
  303.  
  304. /*  de_diskio.c  */
  305.  
  306. void  Read_Disk();
  307. void  Read_Block();
  308. void  Read_Super_Block();
  309. void  Read_Bit_Maps();
  310. off_t Search();
  311. void  Write_Word();
  312.  
  313.  
  314. /*  de_recover.c  */
  315.  
  316. int   Path_Dir_File();
  317. char *File_Device();
  318. ino_t Find_Deleted_Entry();
  319. off_t Recover_Blocks();
  320.  
  321.  
  322. #undef    printf            /*  Because fs/const.h    */
  323.                     /*  defines it.        */
  324.